// !@#$McCaBe-InStRuMeNtAtIoN$#@!
// Instrumented with the McCabe Java Parser
// Version: 8.1.0.1 - 20110309
// Using Path Vector Instrumentation
// Date: Sun Apr 01 2012 20:38:10
package Driver;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

import EventManager.Administrator;
import EventManager.ClientPerson;
import EventManager.CreateBookingRequest;
import EventManager.CreateEventAdminRequest;
import EventManager.RequestProcessor;
import EventManager.RequestStatus;
import EventManager.ViewAllEventsRequest;
import EventManager.ViewBookingsForEventAdminRequest;
import Model.Event;
import Model.Person;
import Model.Seat;
import Model.Venue;
import Model.VenueTimeslot;
import Service.InputManager;
import Service.OutputManager;

import com.mccabe.*;


class ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4 {
    static java.lang.Object info[];
    static {
        info = new java.lang.Object[2];
        info[0] = new Integer(-1);
        info[1] = new String("R:\\yu\\Concordia\\SOEN 344 Design II\\Term Assignment\\Code Repo\\trunk\\Iteration 3\\ERS\\src\\Driver\\ManualOperationStrategy.java");
    }
}


/**
 * Manual operation mode strategy
 * 
 * @author Yury Kitaev
 *
 */
public class ManualOperationStrategy implements OperationStrategy
{
	@Override
	public void run()
	{
int _mcFreq_349e6bc1e19ed835589d325987f45af7[] = new int[3];
PathVec_ERS_Iter3.enterMethod(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,0,_mcFreq_349e6bc1e19ed835589d325987f45af7,0);

		OutputManager.println("Manual Operation Mode Engaged.\n");
		
		String firstName = "";
		String lastName = "";
		OutputManager.print("Enter operator's name (First Last): ");
		Scanner kb = new Scanner(System.in);
		firstName = kb.next();
		lastName = kb.nextLine();
		
		OutputManager.offerChoiceMenu("What role does " + firstName  + " have in the system?", "Administrator (can view events, create events, view bookings)", "Client (can view events and register for events)");
		int role = InputManager.readInput(1, 2);
		
		if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,0,_mcFreq_349e6bc1e19ed835589d325987f45af7,1,2,
PathVec_ERS_Iter3.testCondition(1 == role
))
)
		{
			Person person = new Administrator(firstName, lastName);
			OutputManager.println("Person created: " + person + "\n");
			playAdmin(person);
		}
		else
		{
			Person person = new ClientPerson(firstName, lastName);
			OutputManager.println("Person created: " + person + "\n");
			playClient(person);
		}
	}
	
	/**
	 * Manual admin role play
	 * @param person
	 */
	protected void playAdmin(Person person)
	{
int _mcFreq_14684cc801527045a13fd5669c2dc69b[] = new int[9];
PathVec_ERS_Iter3.enterMethod(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,1,_mcFreq_14684cc801527045a13fd5669c2dc69b,0);

		OutputManager.println("\nHello, " + person.getFirstName() + ", you are logged in as ADMIN!\n");
		
		int response = 0;
		while (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,1,_mcFreq_14684cc801527045a13fd5669c2dc69b,1,2,
PathVec_ERS_Iter3.testCondition(response != 4
))
)
		{
			OutputManager.offerChoiceMenu("What would you like to do next?", "View all available events", "Create an event", "View Bookings for Event", "Return to main menu");
			response = InputManager.readInput(1, 4);
			if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,1,_mcFreq_14684cc801527045a13fd5669c2dc69b,3,4,
PathVec_ERS_Iter3.testCondition(1 == response
))
)
			{
				viewAllEvents();
			}
			else if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,1,_mcFreq_14684cc801527045a13fd5669c2dc69b,5,6,
PathVec_ERS_Iter3.testCondition(2 == response
))
)
			{
				createEvent(person);
			}
			else if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,1,_mcFreq_14684cc801527045a13fd5669c2dc69b,7,8,
PathVec_ERS_Iter3.testCondition(3 == response
))
)
			{
				viewBookings(person);
			}
		}
	}
	
	/**
	 * Initiates view booking sequence
	 * @param person Person who works with the terminal. Should be an administrator.
	 */
	private void viewBookings(Person person) 
	{
int _mcFreq_8ca811b759f94315e4ea7e4a13981fd0[] = new int[3];
PathVec_ERS_Iter3.enterMethod(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,2,_mcFreq_8ca811b759f94315e4ea7e4a13981fd0,0);

		Scanner kb = new Scanner (System.in);
		
		OutputManager.println("\nCHOOSE AN EVENT TO VIEW BOOKINGS FOR:\n ");
		
		// Show all events first
		
		ViewAllEventsRequest r = new ViewAllEventsRequest(false);
		
		RequestProcessor.process(r);
		
		
{
for (Event e : r.getEvents())
		{
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,2,_mcFreq_8ca811b759f94315e4ea7e4a13981fd0,1,0,true);

			OutputManager.println(e.toString());
		}
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,2,_mcFreq_8ca811b759f94315e4ea7e4a13981fd0,2,0,true);

}

		
		OutputManager.print("\nEnter Event ID: ");
		int id = kb.nextInt();
		
		ViewBookingsForEventAdminRequest viewreq = new ViewBookingsForEventAdminRequest((Administrator)person, id);
		RequestProcessor.process(viewreq, (Administrator)person);
		ViewBookingsForEventAdminRequestView viewer = new ViewBookingsForEventAdminRequestView();
		viewer.view(viewreq);
		
	}

	/**
	 * Manual event creation
	 */
	private void createEvent(Person user) 
	{
int _mcFreq_e5206617568f495da12025e9064a26be[] = new int[9];
PathVec_ERS_Iter3.enterMethod(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,0);

		Scanner kb = new Scanner (System.in);
		
		OutputManager.print("Event title: ");
		String title = kb.nextLine();

		
		boolean dateOk = false;
		Date date = null;
		while (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,1,2,
PathVec_ERS_Iter3.testCondition(!dateOk
))
)
		{
			
{boolean __MCCABE_SKIPNEXT_EVENT_34 = false;
try {try
			{
				OutputManager.print("Date and time (yyyy-MM-dd HH:mm): ");
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				date = dateFormat.parse(kb.nextLine());
				dateOk = true;
			}
			catch (ParseException e)
			{
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,3,0,true);
__MCCABE_SKIPNEXT_EVENT_34 = true;

				OutputManager.println("Wrong format, try again.");
			}
if (!__MCCABE_SKIPNEXT_EVENT_34)

PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,5,0,true);
__MCCABE_SKIPNEXT_EVENT_34 = true;

} finally {
    if (!__MCCABE_SKIPNEXT_EVENT_34)
        PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,4,0,true);
}}

		}
		OutputManager.print("Duration (min): ");
		int duration = kb.nextInt();
		
		OutputManager.print("Capacity (persons): ");
		int capacity = kb.nextInt();
		
		OutputManager.print("Event venue: ");
		String venue = kb.next();
		
		
		Venue venuespec = new Venue(venue, "", capacity);
		VenueTimeslot venueTimeslot = new VenueTimeslot(venuespec);
		
		
		CreateEventAdminRequest request = null;
		Administrator admin = null;
		
{boolean __MCCABE_SKIPNEXT_EVENT_39 = false;
try {try
		{
			request = new CreateEventAdminRequest(title, date, duration, capacity, venueTimeslot, admin );
			admin = (Administrator) user;
			RequestProcessor.process(request, admin);
			RequestView viewer = new RequestView();
			viewer.view(request);
			OutputManager.print("\n\nEvent added.\nYou can now view the event list to see it.\n\n");
		}
		catch (Exception e)
		{
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,6,0,true);
__MCCABE_SKIPNEXT_EVENT_39 = true;

			OutputManager.println("Error: You must be an administrator to do this!");
			return;
		}
if (!__MCCABE_SKIPNEXT_EVENT_39)

PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,8,0,true);
__MCCABE_SKIPNEXT_EVENT_39 = true;

} finally {
    if (!__MCCABE_SKIPNEXT_EVENT_39)
        PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,3,_mcFreq_e5206617568f495da12025e9064a26be,7,0,true);
}}

	}

	/**
	 * Manual client role play
	 * @param person
	 */
	protected void playClient (Person person)
	{
int _mcFreq_d843559db579ee25969b8069aafe2aa4[] = new int[7];
PathVec_ERS_Iter3.enterMethod(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,4,_mcFreq_d843559db579ee25969b8069aafe2aa4,0);

		OutputManager.println("\nHello, " + person.getFirstName() + ", welcome to ERS.\n");
		
		int response = 0;
		while (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,4,_mcFreq_d843559db579ee25969b8069aafe2aa4,1,2,
PathVec_ERS_Iter3.testCondition(response != 3
))
)
		{
			OutputManager.offerChoiceMenu("What would you like to do next?", "View all available events", "Register for an event", "Return to main menu");
			response = InputManager.readInput(1, 3);
			if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,4,_mcFreq_d843559db579ee25969b8069aafe2aa4,3,4,
PathVec_ERS_Iter3.testCondition(1 == response
))
)
			{
				viewAllEvents();
			}
			else if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,4,_mcFreq_d843559db579ee25969b8069aafe2aa4,5,6,
PathVec_ERS_Iter3.testCondition(2 == response
))
)
			{
				registerForEvent(person);
			}
		}
	}

	/**
	 * Manual event registration
	 * @param person
	 */
	private void registerForEvent(Person person) 
	{
int _mcFreq_d03339344411629e95725d738d702040[] = new int[33];
PathVec_ERS_Iter3.enterMethod(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,0);

		OutputManager.println("\n*** Manual Event Registration ***\n");
		
		// Show available events
		ViewAllEventsRequest eventReq = new ViewAllEventsRequest(false);
		RequestProcessor.process(eventReq);
		
		// The following events are available:
		OutputManager.println("OPEN EVENTS:");
		
{
for (Event e : eventReq.getEvents())
		{
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,1,0,true);

			OutputManager.println(e.toString());
		}
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,2,0,true);

}

		
		Scanner kb = new Scanner(System.in);
		Event event = null;
		int id = 0;
		
		while (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,3,4,
PathVec_ERS_Iter3.testCondition(null == event
))
)
		{
			OutputManager.print("\nEnter event ID: ");
			
			id = kb.nextInt();
			
			
{
boolean  MCCABE_EVENT_58 = true;
for (Event e : eventReq.getEvents())
			{
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,5,0,true);

				if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,7,8,
PathVec_ERS_Iter3.testCondition(id == e.getId()
))
)
				{
					event = e;
					
{
 MCCABE_EVENT_58 = false; 
break;
}

				}
			}
if ( MCCABE_EVENT_58) PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,6,0,true);

}
	
		}
			
		int seat = 0;
		while (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,9,10,
PathVec_ERS_Iter3.testCondition(0 == seat
))
)
		{
			OutputManager.println("\nSeat map: ");
			for (int i = 0; 
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,11,12,
PathVec_ERS_Iter3.testCondition(i < event.getVenue().getSeats().size()
))
; ++i)
			{
				Seat s =  event.getVenue().getSeats().get(i);
				if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,13,14,
PathVec_ERS_Iter3.testCondition(s.getNumber() < 10
))
)
				{
					OutputManager.print(s.getNumber() + "   ");
				}
				else
				{
					OutputManager.print(s.getNumber() + "  ");
				}
			}
			OutputManager.println("");
			for (int i = 0; 
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,15,16,
PathVec_ERS_Iter3.testCondition(i < event.getVenue().getSeats().size()
))
; ++i)
			{
				Seat s =  event.getVenue().getSeats().get(i);
				if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,17,18,
PathVec_ERS_Iter3.testCondition(s.getNumber() < 10
))
)
				{
					OutputManager.print((
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,19,20,
PathVec_ERS_Iter3.testCondition(s.isTaken()
))
 ? " X" : "__") + "  ");
				}
				else
				{
					OutputManager.print((
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,21,22,
PathVec_ERS_Iter3.testCondition(s.isTaken()
))
 ? " X" : "__") + "  ");
				}
			}

			OutputManager.print("\nEnter seat number: ");
			seat = kb.nextInt();
			
			if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,23,24,
PathVec_ERS_Iter3.testCondition(seat <= 0
))
 || 
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,25,26,
PathVec_ERS_Iter3.testCondition(seat > event.getVenue().getSeats().size()
))
) seat = 0;
		}
		
		OutputManager.println("\nCONFIRM REGISTRATION: ");
		OutputManager.println(event.toString() + ", seat " + seat);
		OutputManager.offerChoiceMenu("Please choose: ", "Confirm registration", "Cancel");
		int response = InputManager.readInput(1, 2);
		
		if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,27,28,
PathVec_ERS_Iter3.testCondition(1 == response
))
)
		{
			CreateBookingRequest r = new CreateBookingRequest(person, event.getId(), seat);
			RequestProcessor.process(r);
			if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,29,30,
PathVec_ERS_Iter3.testCondition(r.getStatus() == RequestStatus.Sustained
))
)
			{
				OutputManager.println("\nREGISTRATION SUCCESS on seat " + r.getBooking().getSeat().getNumber() + (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,5,_mcFreq_d03339344411629e95725d738d702040,31,32,
PathVec_ERS_Iter3.testCondition(seat != r.getBooking().getSeat().getNumber()
))
 ? ("(seat " + seat + " was taken) ") : "" ));
			}
			else
			{
				OutputManager.println("No seats where found!! Registration aborted.");
			}
		}
		
	}

	/**
	 * Requests for all events and displays them
	 */
	private void viewAllEvents() 
	{
int _mcFreq_554c7397452c0a67e1e1a6eccbc91679[] = new int[3];
PathVec_ERS_Iter3.enterMethod(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,6,_mcFreq_554c7397452c0a67e1e1a6eccbc91679,0);

		OutputManager.offerChoiceMenu("What kind of events would you like to see?", "All events in the catalog", "Only open events");
		int response = InputManager.readInput(1, 2);
		ViewAllEventsRequest r = null;
		if (
PathVec_ERS_Iter3.decision(ManualOperationStrategy_f4b20b7c83b92fb249770d89ea14e7e4.info,6,_mcFreq_554c7397452c0a67e1e1a6eccbc91679,1,2,
PathVec_ERS_Iter3.testCondition(1 == response
))
)
		{
			r = new ViewAllEventsRequest(false);
		}
		else
		{
			r = new ViewAllEventsRequest(true);
		}
		r = (ViewAllEventsRequest) RequestProcessor.process(r);
		
		RequestView viewer = new ViewAllEventsRequestView();
		viewer.view(r);
	}
}
